//; ---------------------------------------------------------------------------
//; Object 44 - edge walls (GHZ)
//; ---------------------------------------------------------------------------
#include "edgewalls.h"

#include "../../sprite.h"
#include "../../collision.h"
#include "../../objectsystemNEWER.h"

static object *obj;

//; ---------------------------------------------------------------------------
//; Sprite mappings - walls (GHZ)
//; ---------------------------------------------------------------------------
byte M_Edge_Shadow[21] = { 4,
		 0xE0, 5, 0,	4, 0xF8,        //; light with shadow
		 0xF0, 5, 0,	8, 0xF8,
		 0,    5, 0,    8, 0xF8,
		 0x10, 5, 0,	8, 0xF8
};
byte M_Edge_Light[21] =  { 4,
		 0xE0, 5,   0,	8, 0xF8,	//; light with no shadow
		 0xF0, 5,   0,	8, 0xF8,
		 0,    5,   0,  8, 0xF8,
		 0x10, 5,   0,	8, 0xF8
};
byte M_Edge_Dark[21] =   { 4,
		 0xE0, 5,   0,	0, 0xF8,	//; all shadow
		 0xF0, 5,   0,	0, 0xF8,
		 0,    5,   0,  0, 0xF8,
		 0x10, 5,   0,	0, 0xF8
};

byte *Map_Edge[3] = { M_Edge_Shadow, M_Edge_Light, M_Edge_Dark };

//----------

void (*Edge_Index[3])() = { Edge_Main, Edge_Solid, Edge_Display };

//EdgeWalls:				; XREF: Obj_Index
void EdgeWalls(object *_obj)
{
    obj = _obj;

    //moveq	#0,d0
    //move.b	obRoutine(a0),d0
    byte routine = obj->Routine/2;

    //move.w	Edge_Index(pc,d0.w),d1
    //jmp	Edge_Index(pc,d1.w)
    (*Edge_Index[routine])();
}

//Edge_Main:	; Routine 0
void Edge_Main()
{
    //addq.b	#2,obRoutine(a0)
    obj->Routine = obj->Routine + 2;

    //move.l	#Map_Edge,obMap(a0)
    obj->Map = Map_Edge;

    //move.w	#$434C,obGfx(a0)
    obj->Gfx = 0x434C;

    //ori.b	#4,obRender(a0)
    obj->Render = obj->Render | 4;

    //move.b	#8,obActWid(a0)
    obj->ActionWidth = 8;

    //move.b	#6,obPriority(a0)
    obj->Priority = 6;

    //move.b	obSubtype(a0),obFrame(a0) ; copy object type number to frame number
    obj->Frame = obj->Subtype;
 
    byte solidBit = (obj->Frame & 0x10);
    //bclr	#4,obFrame(a0)	; clear	4th bit	(deduct	$10)
    obj->Frame = obj->Frame - solidBit;

    //beq.s	Edge_Solid	; make object solid if 4th bit = 0
    if (solidBit == 0) { Edge_Solid(); }
    else
    {
        //addq.b	#2,obRoutine(a0)
        obj->Routine = obj->Routine + 2;

	//bra.s	Edge_Display	; don't make it solid if 4th bit = 1
        Edge_Display();
    }
}   //; ===========================================================================

//Edge_Solid:	; Routine 2
void Edge_Solid()
{
    //move.w	#$13,d1
    word width = 19;

    //move.w	#$28,d2
    word jumpHeight = 40;

    //bsr.w	Obj44_SolidWall
    Obj44_SolidWall(obj, width, jumpHeight);

    Edge_Display();
}

//Edge_Display:	; Routine 4
void Edge_Display()
{
    //bsr.w	DisplaySprite
    DisplaySprite(obj);

    //out_of_range	DeleteObject
    if (out_of_range(obj)) { DeleteObject(obj); }

}   //rts	



